package com.luoyu.kafka;

import com.luoyu.kafka.entity.Message;
import com.luoyu.kafka.service.KafkaService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@Slf4j
// 获取启动类，加载配置，确定装载 Spring 程序的装载方法，它回去寻找 主配置启动类（被 @SpringBootApplication 注解的）
@SpringBootTest
class KafkaApplicationTests {

    @Autowired
    private KafkaService kafkaService;

    @Test
    void sendMessageTest() throws Exception{
        Message<String> message = new Message();
        message.setId("1");
        message.setContent("test");
        // 发送消息
        kafkaService.sendMessage(message.toString());
        // 让主线程睡眠10秒
        Thread.currentThread().sleep(10000);
    }

    @BeforeEach
    void testBefore(){
        log.info("测试开始!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    }

    @AfterEach
    void testAfter(){
        log.info("测试结束!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    }

}
